{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取数据\n",
    "data = pd.read_csv('./data/stock_day.csv')\n",
    "data = data.drop([\"ma5\",\"ma10\",\"ma20\",\"v_ma5\",\"v_ma10\",\"v_ma20\"], axis=1)\n",
    "# data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([1, 0, 4, 3, 2, 1, 0, 4, 3, 2,\n",
       "            ...\n",
       "            4, 3, 2, 1, 0, 4, 3, 2, 1, 0],\n",
       "           dtype='int64', length=643)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取日期\n",
    "week = pd.to_datetime(data.index).weekday\n",
    "week"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>turnover</th>\n",
       "      <th>week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>23.53</td>\n",
       "      <td>25.88</td>\n",
       "      <td>24.16</td>\n",
       "      <td>23.53</td>\n",
       "      <td>95578.03</td>\n",
       "      <td>0.63</td>\n",
       "      <td>2.68</td>\n",
       "      <td>2.39</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>22.80</td>\n",
       "      <td>23.78</td>\n",
       "      <td>23.53</td>\n",
       "      <td>22.80</td>\n",
       "      <td>60985.11</td>\n",
       "      <td>0.69</td>\n",
       "      <td>3.02</td>\n",
       "      <td>1.53</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>22.88</td>\n",
       "      <td>23.37</td>\n",
       "      <td>22.82</td>\n",
       "      <td>22.71</td>\n",
       "      <td>52914.01</td>\n",
       "      <td>0.54</td>\n",
       "      <td>2.42</td>\n",
       "      <td>1.32</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>22.25</td>\n",
       "      <td>22.76</td>\n",
       "      <td>22.28</td>\n",
       "      <td>22.02</td>\n",
       "      <td>36105.01</td>\n",
       "      <td>0.36</td>\n",
       "      <td>1.64</td>\n",
       "      <td>0.90</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>21.49</td>\n",
       "      <td>21.99</td>\n",
       "      <td>21.92</td>\n",
       "      <td>21.48</td>\n",
       "      <td>23331.04</td>\n",
       "      <td>0.44</td>\n",
       "      <td>2.05</td>\n",
       "      <td>0.58</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.48</td>\n",
       "      <td>14.28</td>\n",
       "      <td>13.13</td>\n",
       "      <td>179831.72</td>\n",
       "      <td>1.12</td>\n",
       "      <td>8.51</td>\n",
       "      <td>6.16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.45</td>\n",
       "      <td>13.16</td>\n",
       "      <td>12.87</td>\n",
       "      <td>93180.39</td>\n",
       "      <td>0.26</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3.19</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.61</td>\n",
       "      <td>67075.44</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2.30</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>13.06</td>\n",
       "      <td>12.70</td>\n",
       "      <td>12.52</td>\n",
       "      <td>139071.61</td>\n",
       "      <td>0.18</td>\n",
       "      <td>1.44</td>\n",
       "      <td>4.76</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.67</td>\n",
       "      <td>12.52</td>\n",
       "      <td>12.20</td>\n",
       "      <td>96291.73</td>\n",
       "      <td>0.32</td>\n",
       "      <td>2.62</td>\n",
       "      <td>3.30</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>643 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low     volume  price_change  p_change  \\\n",
       "2018-02-27  23.53  25.88  24.16  23.53   95578.03          0.63      2.68   \n",
       "2018-02-26  22.80  23.78  23.53  22.80   60985.11          0.69      3.02   \n",
       "2018-02-23  22.88  23.37  22.82  22.71   52914.01          0.54      2.42   \n",
       "2018-02-22  22.25  22.76  22.28  22.02   36105.01          0.36      1.64   \n",
       "2018-02-14  21.49  21.99  21.92  21.48   23331.04          0.44      2.05   \n",
       "...           ...    ...    ...    ...        ...           ...       ...   \n",
       "2015-03-06  13.17  14.48  14.28  13.13  179831.72          1.12      8.51   \n",
       "2015-03-05  12.88  13.45  13.16  12.87   93180.39          0.26      2.02   \n",
       "2015-03-04  12.80  12.92  12.90  12.61   67075.44          0.20      1.57   \n",
       "2015-03-03  12.52  13.06  12.70  12.52  139071.61          0.18      1.44   \n",
       "2015-03-02  12.25  12.67  12.52  12.20   96291.73          0.32      2.62   \n",
       "\n",
       "            turnover  week  \n",
       "2018-02-27      2.39     1  \n",
       "2018-02-26      1.53     0  \n",
       "2018-02-23      1.32     4  \n",
       "2018-02-22      0.90     3  \n",
       "2018-02-14      0.58     2  \n",
       "...              ...   ...  \n",
       "2015-03-06      6.16     4  \n",
       "2015-03-05      3.19     3  \n",
       "2015-03-04      2.30     2  \n",
       "2015-03-03      4.76     1  \n",
       "2015-03-02      3.30     0  \n",
       "\n",
       "[643 rows x 9 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 向原始数据中添加日期列\n",
    "data['week'] = week\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 统计股票涨跌情况，用1表示涨，用0表\n",
    "p_n = np.where(data['p_change']>0, 1, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 向原始数据中添加股票涨跌列\n",
    "data['p_n'] = p_n\n",
    "# data.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>col_0</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>63</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>55</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>61</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>59</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "col_0   0   1\n",
       "row_0        \n",
       "0      63  62\n",
       "1      55  76\n",
       "2      61  71\n",
       "3      63  65\n",
       "4      59  68"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用交叉表查看周n和股票涨跌的关系\n",
    "count = pd.crosstab(week, p_n)\n",
    "count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>col_0</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.504000</td>\n",
       "      <td>0.496000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.419847</td>\n",
       "      <td>0.580153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.462121</td>\n",
       "      <td>0.537879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.492188</td>\n",
       "      <td>0.507812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.464567</td>\n",
       "      <td>0.535433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "col_0         0         1\n",
       "row_0                    \n",
       "0      0.504000  0.496000\n",
       "1      0.419847  0.580153\n",
       "2      0.462121  0.537879\n",
       "3      0.492188  0.507812\n",
       "4      0.464567  0.535433"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每周n的涨跌情况\n",
    "sum = count.sum(axis=1)\n",
    "count = count.div(sum, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x201281df808>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABIAAAAHaCAYAAAB4hTJsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaBUlEQVR4nO3df6xf933X8dd7sdPa8dwk5MYsaVnwElBaUNbW0Lh4xQ1rGyvtKoU2TVeCygoRZQj+g4YECBNiVZgK2qREBLwfEtukFNpoUxfVYzRNkJxWN/25EKYh5Kj1lPiOePZMEwjZhz/ut7OT2sT+3u/Nsd9+PP7x+Z5vvue87x9f3atnPuecGmMEAAAAgL6+b+oBAAAAAFhfAhAAAABAcwIQAAAAQHMCEAAAAEBzAhAAAABAcwIQAAAAQHMbpjjpZZddNq666qopTg0AAADQ0uOPP/77Y4ylk703SQC66qqrsry8PMWpAQAAAFqqqqdO9Z5LwAAAAACaE4AAAAAAmhOAAAAAAJoTgAAAAACaE4AAAAAAmhOAAAAAAJqb5DHwAAAAAGt19OjRHDp0KC+88MLUo6y7jRs35vLLL8/WrVvn+rwABAAAAJxzjh49mmeeeSZXXnllNm3alKqaeqR1M8bIc889l4MHDybJXBHIJWAAAADAOefQoUO58sors3nz5tbxJ0mqKps3b86VV16ZQ4cOzXUMAQgAAAA457zwwgvZtGnT1GO8qjZt2jT35W4CEAAAAHBO6r7y5+XW8vMKQAAAAADNuQk0AAAA0MZVn/jcJOc98MmbJjnv6bICCAAAAGAihw8fzgc+8IFs3bo1b33rW/ONb3xjXc5jBRAAAADARD784Q/n0KFD2b9/f772ta/l/e9/f775zW9my5YtCz2PFUAAAAAAE3jiiSfy+c9/Pvfee2/e9KY35SMf+UiuvfbaPPjggws/lwAEA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9W/rKrPz16/pqp+taq+WFW/XFUXVtVyVV1eVc9U1Q9U1W+c4nC7kzww296XZNer8CMAAJwRAQgAOB9dn2T/GOM9s9d/K8lvjzH+cpLfTfITSf5Hkvck+XKSdyf5yimOdVGSg7PtZ5NsW6+hAQDmJQABAOej3x5jfOaE129M8qXZ9mNJrs1q8LklyeeSfDDJ46c41rEkm2bbW+LvKwDgLOQPFADgfHTsZa+fyOqqoMz+fSLJV5PckOQ/ZXUl0KlWAD2e45d9XZfkwCIHBQBYhA1TDwAAcBb4d0l+saoeSfKtJP8iyeuSPJXVS8EOjTGeOsVnH0zyaFVdkWRPjockAICzRo0xpp4BAOCcVlWXJHlXkkfGGE9PPQ8AwMsJQAAAp6mqHn7ZriNjjPdPMQsAwJkQgAAAAACacxNoAAAAgOYEIAAAAIDmBCAAAACA5gQgAAAAgOYEIAAAAIDm/h8m5tMU8M0DOAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 1440x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "count.plot(kind='bar', figsize=(20, 8), stacked=True)  # stacked=True表示柱状图进行堆积\n",
    "plt.legend(fontsize=15)\n",
    "# plt.xticks(fontsize=20, color='w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_n</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.496000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.580153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.537879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.507812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.535433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           p_n\n",
       "week          \n",
       "0     0.496000\n",
       "1     0.580153\n",
       "2     0.537879\n",
       "3     0.507812\n",
       "4     0.535433"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 透视表\n",
    "data.pivot_table(['p_n'], index='week')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
